package cn.iocoder.yudao.module.blog.convert.spacecomment;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.blog.controller.app.space.commentvo.AppBlogSpaceCommentRespVO;
import cn.iocoder.yudao.module.blog.controller.app.space.vo.AppBlogSpaceRespVO;
import cn.iocoder.yudao.module.blog.convert.base.BlogConvert;
import cn.iocoder.yudao.module.blog.dal.dataobject.space.BlogSpaceDO;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.member.controller.admin.user.vo.MemberUserRespVO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.module.blog.controller.admin.spacecomment.vo.*;
import cn.iocoder.yudao.module.blog.dal.dataobject.spacecomment.BlogSpaceCommentDO;

/**
 * 动态评论 Convert
 *
 * @author 曹建伟
 */
@Mapper
public interface BlogSpaceCommentConvert {

    BlogSpaceCommentConvert INSTANCE = Mappers.getMapper(BlogSpaceCommentConvert.class);

    BlogSpaceCommentDO convert(BlogSpaceCommentCreateReqVO bean);

    BlogSpaceCommentDO convert(BlogSpaceCommentUpdateReqVO bean);

    BlogSpaceCommentRespVO convert(BlogSpaceCommentDO bean);

    List<BlogSpaceCommentRespVO> convertList(List<BlogSpaceCommentDO> list);

    PageResult<BlogSpaceCommentRespVO> convertPage(PageResult<BlogSpaceCommentDO> page);

    List<BlogSpaceCommentExcelVO> convertList02(List<BlogSpaceCommentDO> list);

    default AppBlogSpaceCommentRespVO convertApp(BlogSpaceCommentDO bean, MemberUserRespDTO memberUserRespDTO){
        if ( bean == null ) {
            return null;
        }

        AppBlogSpaceCommentRespVO appBlogSpaceCommentRespVO = new AppBlogSpaceCommentRespVO();

        appBlogSpaceCommentRespVO.setMember(BlogConvert.INSTANCE.covnertMember(memberUserRespDTO));
        appBlogSpaceCommentRespVO.setId(bean.getId());
        appBlogSpaceCommentRespVO.setSpaceId(bean.getSpaceId());
        appBlogSpaceCommentRespVO.setRespondCommentId(bean.getRespondCommentId());
        appBlogSpaceCommentRespVO.setContent(bean.getContent());
        appBlogSpaceCommentRespVO.setCreateTime(bean.getCreateTime());
        appBlogSpaceCommentRespVO.setMemberId(bean.getMemberId());

        return appBlogSpaceCommentRespVO;
    }

    default List<AppBlogSpaceCommentRespVO> convertAppList(List<BlogSpaceCommentDO> blogSpaceCommentDOList, Map<Long, MemberUserRespDTO> memberMap){
        List<AppBlogSpaceCommentRespVO> list = new ArrayList<>();
        blogSpaceCommentDOList.forEach(blogSpaceCommentDO -> {
            list.add(convertApp(blogSpaceCommentDO, memberMap.get(blogSpaceCommentDO.getMemberId())));
        });

        return list;
    }

    default PageResult<AppBlogSpaceCommentRespVO> convertAppPage(PageResult<BlogSpaceCommentDO> page, Map<Long, MemberUserRespDTO> memberMap ){
        if ( page == null ) {
            return null;
        }

        PageResult<AppBlogSpaceCommentRespVO> pageResult = new PageResult<AppBlogSpaceCommentRespVO>();
        List<AppBlogSpaceCommentRespVO> list = convertAppList(page.getList(), memberMap);

        pageResult.setList(list);
        pageResult.setTotal(page.getTotal());

        return pageResult;
    }

}
